package com.example.brisk.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.example.brisk.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on xxxx.
 * Sa-Token 权限认证，在线文档：https://sa-token.cc
 * @author yangjian.
 */
@Api(value = "user", tags = "login api")
@RestController
@RequestMapping("/api/user/")
public class LoginController {
    @ApiOperation(value = "登录", notes = "账号密码")
    @GetMapping("doLogin")
    public R doLogin(String name, String pwd) {
        // 此处仅作模拟示例，真实项目需要从数据库中查询数据进行比对
        if("zhang".equals(name) && "123456".equals(pwd)) {
            StpUtil.login(10001);
            return R.success("登录成功");
        }
        return R.fail("登录失败");
    }
    @ApiOperation(value = "获取登录状态", notes = "")
    @GetMapping("isLogin")
    public R isLogin() {
        return R.data(StpUtil.isLogin());
    }

    @ApiOperation(value = "获取token", notes = "")
    @GetMapping("tokenInfo")
    public R tokenInfo() {
        return R.data(StpUtil.getTokenInfo());
    }

    @ApiOperation(value = "登出", notes = "")
    @GetMapping("logout")
    public R logout() {
        StpUtil.logout();
        return R.success("登出");
    }

}
